/**
 * Copyright (C) 2010 Cloudfarming <info@cloudfarming.nl>
 *
 * Licensed under the Eclipse Public License - v 1.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *         http://www.eclipse.org/legal/epl-v10.html
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package nl.cloudfarming.client.core;

import javax.persistence.EntityManager;
import javax.persistence.EntityTransaction;
import javax.persistence.FlushModeType;
import javax.persistence.LockModeType;
import javax.persistence.Query;

/**
 *
 * @author Timon Veenstra
 */
public class ProxyEntityManager implements EntityManager{

    private final EntityManager localEntityManager;
    private boolean online = false;

    public ProxyEntityManager(EntityManager localEntityManager) {
        this.localEntityManager = localEntityManager;
    }

    public boolean isOnline() {
        return online;
    }

    public void setOnline(boolean online) {
        this.online = online;
    }

    @Override
    public void persist(Object entity) {
        this.localEntityManager.persist(entity);
    }

    @Override
    public <T> T merge(T entity) {
        return this.localEntityManager.merge(entity);
    }

    @Override
    public void remove(Object entity) {
        this.localEntityManager.remove(entity);
    }

    @Override
    public <T> T find(Class<T> entityClass, Object primaryKey) {
        return this.localEntityManager.find(entityClass, primaryKey);
    }

    @Override
    public <T> T getReference(Class<T> entityClass, Object primaryKey) {
        return this.localEntityManager.getReference(entityClass, primaryKey);
    }

    @Override
    public void flush() {
        this.localEntityManager.flush();
    }

    @Override
    public void setFlushMode(FlushModeType flushMode) {
        this.localEntityManager.setFlushMode(flushMode);
    }

    @Override
    public FlushModeType getFlushMode() {
        return this.localEntityManager.getFlushMode();
    }

    @Override
    public void lock(Object entity, LockModeType lockMode) {
        this.localEntityManager.lock(entity, lockMode);
    }

    @Override
    public void refresh(Object entity) {
        this.localEntityManager.refresh(entity);
    }

    @Override
    public void clear() {
        this.localEntityManager.clear();
    }

    @Override
    public boolean contains(Object entity) {
        return this.localEntityManager.contains(entity);
    }

    @Override
    public Query createQuery(String qlString) {
        return this.localEntityManager.createQuery(qlString);
    }

    @Override
    public Query createNamedQuery(String name) {
        return this.localEntityManager.createNamedQuery(name);
    }

    @Override
    public Query createNativeQuery(String sqlString) {
        return this.localEntityManager.createNativeQuery(sqlString);
    }

    @Override
    public Query createNativeQuery(String sqlString, Class resultClass) {
         return this.localEntityManager.createNativeQuery(sqlString, resultClass);
    }

    @Override
    public Query createNativeQuery(String sqlString, String resultSetMapping) {
         return this.localEntityManager.createNativeQuery(sqlString, resultSetMapping);
    }

    @Override
    public void joinTransaction() {
         this.localEntityManager.joinTransaction();
    }

    @Override
    public Object getDelegate() {
         return this.localEntityManager.getDelegate();
    }

    @Override
    public void close() {
        this.localEntityManager.close();
    }

    @Override
    public boolean isOpen() {
         return this.localEntityManager.isOpen();
    }

    @Override
    public EntityTransaction getTransaction() {
         return this.localEntityManager.getTransaction();
    }

}
